﻿using EasyNet.Componets.Core.Inject;
using EasyNet.Componets.Core.Locations;
using EasyNet.Componets.Core.Locations.Baidu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyNet.Componets.Core.Utils
{
    public static class LocationUtil
    {
        private static ILocation _instance;

        public static ILocation Instance
        {
            get
            {
                if (_instance != null)
                {
                    return _instance;
                }
                try
                {
                    _instance = IoC.Resolve<ILocation>();
                }
                catch
                {
                    _instance = new BaiduLocation();
                }

                return _instance;
            }
        }

        public static void SetInstance(ILocation instance)
        {
            _instance = instance;
        }

    

        public static double GetDistance(LocationPoint location1, LocationPoint location2)
        {
            return Instance.GetDistance(location1, location2);
        }

        public static LocationPoint GetLocationByIp(string ip)
        {
            return Instance.GetLocationByIp(ip);
        }

        public static LocationPoint GetLocationByAddress(string address, string city)
        {
            return Instance.GetLocationByAddress(address, city);
        }
    }
}
